
#include "gsl_ext_function.h"
#include "gsl_ext_symbolic_function.h"
#include "GSLFunctionWrapper.h"

GSLFunctionWrapper_f::GSLFunctionWrapper_f(gsl_multimin_function *f):
  GSLFunctionWrapperT< gsl_multimin_function >(f) { }

void GSLFunctionWrapper_f::destroyWrappedObject()
{
  gsl_ext_multimin_function_free(f_);
}

double GSLFunctionWrapper_f::f(const gsl_vector *x) const
{
  return GSL_MULTIMIN_FN_EVAL_F(f_, x);
}

GSLFunctionWrapper_f::Type GSLFunctionWrapper_f::getType() const
{
  return GSLFunctionWrapper::F;
}

GSLFunctionWrapper_fdf::GSLFunctionWrapper_fdf(gsl_multimin_function_fdf *f):
  GSLFunctionWrapperT< gsl_multimin_function_fdf >(f) { }

void GSLFunctionWrapper_fdf::destroyWrappedObject()
{
  gsl_ext_multimin_function_fdf_free(f_);
}

double GSLFunctionWrapper_fdf::f(const gsl_vector *x) const
{
  return GSL_MULTIMIN_FN_EVAL_F(f_, x);
}

void GSLFunctionWrapper_fdf::df(const gsl_vector *x, gsl_vector *g) const
{
  GSL_MULTIMIN_FN_EVAL_DF(f_, x, g);
}

GSLFunctionWrapper_fdf::Type GSLFunctionWrapper_fdf::getType() const
{
  return GSLFunctionWrapper::FDF;
}

GSLFunctionWrapper_fd2f::GSLFunctionWrapper_fd2f(gsl_ext_multimin_function_fd2f *f):
  GSLFunctionWrapperT< gsl_ext_multimin_function_fd2f >(f) { }

void GSLFunctionWrapper_fd2f::destroyWrappedObject()
{
  gsl_ext_multimin_function_fd2f_free(f_);
}

double GSLFunctionWrapper_fd2f::f(const gsl_vector *x) const
{
  return GSL_MULTIMIN_FN_EVAL_F(f_, x);
}

void GSLFunctionWrapper_fd2f::df(const gsl_vector *x, gsl_vector *g) const
{
  GSL_MULTIMIN_FN_EVAL_DF(f_, x, g);
}

void GSLFunctionWrapper_fd2f::d2f(const gsl_vector *x, gsl_matrix *H) const
{
  GSL_EXT_MULTIMIN_FN_EVAL_D2F(f_, x, H);
}

GSLFunctionWrapper_fd2f::Type GSLFunctionWrapper_fd2f::getType() const
{
  return GSLFunctionWrapper::FD2F;
}

GSLFunctionWrapper_f *GSLFunctionWrapperFactory::getInstance(gsl_multimin_function *f)
{
  return new GSLFunctionWrapper_f(f);
}

GSLFunctionWrapper_fdf *GSLFunctionWrapperFactory::getInstance(gsl_multimin_function_fdf *f)
{
  return new GSLFunctionWrapper_fdf(f);
}

GSLFunctionWrapper_fd2f *GSLFunctionWrapperFactory::getInstance(gsl_ext_multimin_function_fd2f *f)
{
  return new GSLFunctionWrapper_fd2f(f);
}
